const http = require("http");
const fs = require("fs");
const url = require("url");
let server = http.createServer((req, res) => {
    res.setHeader("content-type", "text/html;charset=utf-8");

    // 把req.url里真正的地址提取出来  
    // /index?name=123 -----> /index
    let urlObj = url.parse(req.url, true);
    // console.log(urlObj);
    let pathname = urlObj.pathname;
    // /index  和 /index?name=123 是不是一个地址
    if (pathname == "/index") {
        let data = fs.readFileSync("./views/index.html");
        res.write(data)
    } else if (pathname == "/product") {
        let data = fs.readFileSync("./views/product.html");
        res.write(data)
    } else if (pathname == "/users") {
        let data = fs.readFileSync("./views/users.html");
        res.write(data);
    }

    res.end();

})

server.listen(8989);